<template>
  <!-- template最外部只有有一个标签 -->
  <div>
    <div>

      <input v-model="inputValue">
      <button @click='handleCommit'>提交</button>
      <ul>
        <todo-item
          v-for="(value, index) in list"
          :key="index"
          @delete="handleDelete"
          :content="value"
          :index="index">
        </todo-item>
      </ul>
    </div>
  </div>
</template>

<script>

import TodoItem from './components/TodoItem.vue'

export default {
  components: {
    'todo-item': TodoItem
  },
  data () {
    return {
      inputValue: '',
      list: []
    }
  },
  methods: {
    handleCommit: function () {
      this.list.push(this.inputValue)
      this.inputValue = ''
    },
    handleDelete (index) {
      this.list.splice(index, 1)
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
